//
//  RecommendViewController.m
//  YouWoYou
//
//  Created by dlios on 15-3-22.
//  Copyright (c) 2015年 lanou3g.com 蓝欧科技. All rights reserved.
//

#import "RecommendViewController.h"

#import "NetWorkHandle.h"



#import "PhotosBroadCastView.h"
#import "RecommendViewData.h"
#import "MguideModel.h"
#import "DiscountModel.h"
#import "SlideModel.h"


#import "ReferralViewController.h"

@interface RecommendViewController ()

@property (nonatomic, retain) PhotosBroadCastView *photoView;
@property (nonatomic, retain) NSMutableArray *mguideArr;
@property (nonatomic, retain) NSMutableArray *dicountArr;
@property (nonatomic, retain) NSMutableArray *sliderArr;

@end

@implementation RecommendViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self.photoView addtimer];
}

#pragma mark 处理数据
- (void)makeData:(NSMutableDictionary *)dic
{
    // 处理总数据
    RecommendViewData *recommend = [[RecommendViewData alloc] initWithDictionary:dic];
    self.mguideArr = [NSMutableArray array];
    self.dicountArr = [NSMutableArray array];
    self.sliderArr = [NSMutableArray array];
    
    for (NSDictionary *dic in  recommend.mguide) {
        MguideModel *mguide = [[MguideModel alloc] initWithDictonary:dic];
        [self.mguideArr addObject:mguide];
        [mguide release];
    }
    for (NSDictionary *dic in recommend.discount ) {
        DiscountModel *dis = [[DiscountModel alloc] initWithDictionary:dic];
        [self.dicountArr addObject:dis];
        [dis release];
    }
    for (NSDictionary *dic in recommend.slide) {
        SlideModel *slide = [[SlideModel alloc] initWithDictionary:dic];
        NSLog(@"%@", slide.photo);
        [self.sliderArr addObject:slide];
        [slide release];
    }
}

#pragma mark 加载数据
- (void)handleData
{
    NSString *str = @"http://open.qyer.com/qyer/recommands/index?client_id=qyer_android&client_secret=9fcaae8aefc4f9ac4915&v=1&track_user_id=&track_deviceid=865424024133973&track_app_version=6.1.0.2&track_app_channel=xiaomi&track_device_info=armani&track_os=Android4.3&app_installtime=1426735827710&oauth_token=";
    [NetWorkHandle getDataWithUrl:str completion:^(NSData *data) {
       
        NSError *error = nil;
        id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
     
        NSMutableDictionary *dataDic = [result objectForKey:@"data"];
        [self makeData:dataDic];
     
        self.photoView .photoArr = self.sliderArr;
        [self.photoView .collection reloadData];
        
    }];
}

#pragma mark 创建图片导播栏
- (void)makeColection
{
    
    self.photoView = [[PhotosBroadCastView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height / 4)];
    self.photoView .backgroundColor = [UIColor redColor];
    [self.view addSubview:self.photoView ];
    [_photoView release];
    
}


#pragma mark 视图加载
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self makeColection];
    [self handleData];
    
  
    
  
    // Do any additional setup after loading the view.
}

// 状态栏常亮状态
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
